#include "PEventTesting.h"

#include "PiccoloLog.h"

#define BIND_EVENT_FN(fn)   [this](auto&&... args) -> decltype(auto) { return this->fn(std::forward<decltype(args)>(args)...); }
#define REG_EVENT(type)     mObserver->OnEvent<type>([](const type& event) { LOG_T(event.ToString()); } );

static void TestStaticFunc(const Piccolo::PMouseButtonPressEvent &event)
{
    LOG_T(event.ToString());
}

void PEventTesting::TestMemberFunc(const Piccolo::PMouseButtonReleaseEvent &event)
{
    LOG_T(event.ToString());
}

PEventTesting::PEventTesting()
{
    mObserver = std::make_shared<Piccolo::PEventObserver>();
    mObserver->OnEvent<Piccolo::PFrameBufferResizeEvent>([](const Piccolo::PFrameBufferResizeEvent& event)
    {
        LOG_T(event.ToString());
    });
    mObserver->OnEvent<Piccolo::PMouseButtonPressEvent>(TestStaticFunc);
    mObserver->OnEvent<Piccolo::PMouseButtonReleaseEvent>(BIND_EVENT_FN(TestMemberFunc));
    REG_EVENT(Piccolo::PWindowFocusEvent);
    REG_EVENT(Piccolo::PWindowLostFocusEvent);
    REG_EVENT(Piccolo::PWindowMoveEvent);
    REG_EVENT(Piccolo::PWindowCloseEvent);
    REG_EVENT(Piccolo::PKeyInputPressEvent);
    REG_EVENT(Piccolo::PKeyInputReleaseEvent);
    REG_EVENT(Piccolo::PMouseScrollEvent);
}

PEventTesting::~PEventTesting()
{
}
